package com.servlet.form;

import java.io.IOException;
import java.sql.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.listener.ContextListener;
import com.servlet.model.base.Area;
import com.servlet.model.base.Contact;
import com.servlet.model.base.Profile;
import com.servlet.model.base.Status;
import com.servlet.model.database.BaseAcces;

public class OptionForm extends HttpServlet
{
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
	{
		HttpSession session = request.getSession();
		//BaseAcces base = (BaseAcces) this.config.getServletContext().getAttribute("base");

		String email = (String) session.getAttribute("email");
		
		BaseAcces base = ContextListener.base;
		
		int nbn = Integer.parseInt( request.getParameter("news") );
		int nbc = Integer.parseInt( request.getParameter("contacts") );

		System.out.println("Mise a jour du compte : " + email + " " + nbn + " " + nbc);

		Profile profile = ContextListener.base.findProfile(email);
		
		profile.setNb_contacts_par_page(nbc);
		profile.setNb_news_par_page(nbn);
		
		base.updateProfil(profile);

		session.setAttribute("resultat", "Modification réussie !! ");

		response.sendRedirect("options");
	}
}
